package com.xiaoxi.facademode.page;

import com.xiaoxi.facademode.database.DatabaseProperties;
import com.xiaoxi.facademode.writer.HtmlWriter;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.facademode.page
 * @ClassName PageMaker
 * @Description TODO
 * @Date 2023/3/23 20:54
 * @Version 1.0
 */
public class PageMaker {

    private PageMaker() {
    }

    public static void writeWelcomePage(String mailAddr, String filename) {
        Properties properties = DatabaseProperties.getProperties("mailData");
        String mailName = properties.getProperty(mailAddr);
        try {
            HtmlWriter htmlWriter = new HtmlWriter(new FileWriter(filename));
            htmlWriter.title("欢迎来到" + mailName + "的页面！");
            htmlWriter.text("欢迎来到" + mailName + "的页面。");
            htmlWriter.text("等着你的邮件哦！");
            htmlWriter.link(mailAddr, mailName);
            htmlWriter.close();
        } catch (IOException ioException) {
            System.out.println("file is not exist");
        }

    }

    public static void writeLinkPage(String filename) {
        Properties properties = DatabaseProperties.getProperties("mailData");
        try {
            HtmlWriter htmlWriter = new HtmlWriter(new FileWriter(filename));
            htmlWriter.title("link page");
            Enumeration<?> propertyNames = properties.propertyNames();
            while (propertyNames.hasMoreElements()) {
                String element = String.valueOf(propertyNames.nextElement());
                htmlWriter.link(element, properties.getProperty(element));
            }
            htmlWriter.close();
        } catch (IOException ioException) {
            System.out.println("file is not exist");
        }

    }

}
